package com.ccc3gc.servlet;

import com.ccc3gc.serves.UserServes;
import com.ccc3gc.serves.impl.UserServesImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/getUserNames")
public class UserNamesServlet extends HttpServlet {
    UserServes userServes = new UserServesImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String keyWord = req.getParameter("keyWord");
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        if (!"".equals(keyWord)) {
            String string = userServes.queryUserNameS(keyWord);
            out.print(string);
        } else {
            out.print("");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
